<template>

    <vue-table :data-source="tableList">
        <template slot="header">
            <tr>
                <th>ID</th>
                <th>课组名称</th>
                <th>课组序号</th>
                <th>报名上限</th>
                <th>领域</th>
                <th>分类</th>
                <th>操作</th>
            </tr>
        </template>
        <template slot="tbody" slot-scope="props">
            <tr>
                <td>{{props.item.id}}</td>
                <td>{{props.item.class_group_name}}</td>
                <td>{{props.item.class_group_number}}</td>
                <td>{{props.item.peoples}}</td>
                <td>{{$store.state.fieldLists[props.item.field]}}</td>
                <td>{{$store.state.selection[props.item.selection_id]}}</td>
                <td class="col-lg-2">
                    <button title="修改" class="btn btn-white btn-xs m-b-none"
                            v-on:click="showEditDialog(props.item.id)">
                        <i class="fa fa-pencil list-btn-i"></i> 编辑
                    </button>
                    <button class="btn btn-white btn-xs m-b-none" title="删除"
                            v-on:click="showDeleteDialog(props.item.id)">
                        <i class=" fa fa-trash list-btn-i"></i> 删除
                    </button>
                </td>

            </tr>
        </template>
    </vue-table>
</template>

<script>
    export default {
        props: {
            stateManager: {
                type: Object
            }
        },
        data: function () {
            return {
                list: this.$listDataSource({
                    url: 'api/classGroup/classGroup'
                })
            };
        },
        methods: {
            showEditDialog: function (uuid) {
                this.stateManager.editDialogVisible = true;
                this.stateManager.editModelId = uuid;
            },
            showDeleteDialog: function (uuid) {
                this.stateManager.deleteDialogVisible = true;
                this.stateManager.deleteModelId = uuid;
            }
        },
        computed: {
            user(){
                return this.$store.state.user;
            },

            tableList(){
                if (this.stateManager.refreshList) {
                    this.list.fetch();
                    this.stateManager.refreshList = false;
                }
                return this.list;
            }
        }
    }
</script>